package org.stream.answerduel.controller.api;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.stream.answerduel.dto.PageResult;
import org.stream.answerduel.dto.Result;
import org.stream.answerduel.entity.AnswerDetails;
import org.stream.answerduel.service.AnswerDetailsService;
import org.stream.answerduel.vo.AnswerDetailsVo;

import java.util.List;

/**
 *
 * @Auther: 苏建誉
 * @Date: 2019/7/10 11:38
 */
@Api("匹配和比赛接口")
@Slf4j
@CrossOrigin
@RestController
@RequestMapping("/api/AnswerDetails")
public class AnswerDetailsController {
    @Autowired
    private AnswerDetailsService service;

    /**
     * 功能描述：向数据库插入答题信息
     *
     * @param aDVo 对战详细信息实体
     * @return Result
     *
     *
     */
    @ApiOperation(value="添加作答详细信息",notes = "添加作答详细信息")
    @GetMapping("/add")
    public ResponseEntity<Result> add(AnswerDetailsVo aDVo) {
        service.add(aDVo);
        return new ResponseEntity(new Result().ok("添加作答信息成功"), HttpStatus.OK);
    }

    /**
     * 功能描述：通过用户id查询历史对战信息
     *
     * @param id 用户id
     * @param pageNum 当前页码
     * @param pageSize 当前页大小
     */
    @ApiOperation(value="通过用户id查询历史对战信息",notes = "通过用户id查询历史对战信息")
    @GetMapping("/findAnswerDetailsById")
    public ResponseEntity<PageResult<AnswerDetailsVo>> findAnswerDetailsById(Long id, int pageNum, int pageSize){
        Page<AnswerDetailsVo> result=service.findAnswerDetailsById(id,pageNum,pageSize);
        return new ResponseEntity(new PageResult(pageNum,pageSize,result.getContent().size(),result.getContent()),HttpStatus.OK);
    }
}
